﻿Public Class DRGUG
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub queryDrgugGrid()
        Dim objQueryDrgugGrid As New DRGUGCLASS
        Dim dt As DataTable = connect.GetTable(objQueryDrgugGrid.selectMasdrgug_)
        DRGUGGrid.PrimaryGrid.DataSource = dt
    End Sub

    Private Sub DRGUG_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryDrgugGrid()

        DesignForm(Me)
        DesignGrid(DRGUGGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub clearForm()
        UGIDTxt.Clear()
        UGNAMETxt.Clear()
        UGNAME_ENTxt.Clear()
        F_FOODChk.Checked = False
        STATUSChk.Checked = False
    End Sub


    Private Sub DRGUGGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles DRGUGGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวิธีการใช้ยา").Value() IsNot DBNull.Value Then
            UGIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวิธีการใช้ยา").Value()
        Else
            UGIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการใช้ยา(ไทย)").Value() IsNot DBNull.Value Then
            UGNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการใช้ยา(ไทย)").Value()
        Else
            UGNAMETxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการใช้ยา(อังกฤษ)").Value() IsNot DBNull.Value Then
            UGNAME_ENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการใช้ยา(อังกฤษ)").Value()
        Else
            UGNAME_ENTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รับประทาน").Value() = True Then
            F_FOODChk.Checked = True
        Else
            F_FOODChk.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            STATUSChk.Checked = True
        Else
            STATUSChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("masdrgug", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รับประทาน").Value(), "F_FOOD", "UGID", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวิธีการใช้ยา").Value())

        objChkboxUpdate.clickChkboxUpdate("masdrgug", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "UGID", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวิธีการใช้ยา").Value())

        addDrgug.Enabled = False
    End Sub

    Private Sub addDrgug_Click(sender As Object, e As EventArgs) Handles addDrgug.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If UGIDTxt.Text.Length.ToString > 0 And UGNAMETxt.Text.Length.ToString > 0 And UGNAME_ENTxt.Text.Length.ToString > 0 Then
                    Dim objInsertData As New DRGUGCLASS
                    objInsertData.UGID_ = UGIDTxt.Tag
                    objInsertData.UGNAME_ = UGNAMETxt.Text
                    objInsertData.UGNAME_EN_ = UGNAME_ENTxt.Text
                    objInsertData.F_FOOD_ = F_FOODChk.Checked
                    objInsertData.STATUS_ = STATUSChk.Checked


                    If objInsertData.insertMasdrgug() = True Then
                        MsgBox("ท่านได้ทำการเพิ่มรูปแบบการใช้ยาเรียบร้อยแล้ว")
                        queryDrgugGrid()
                        clearForm()
                    End If
                Else
                    MsgBox("โปรดกรุณาระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editDrgug_Click(sender As Object, e As EventArgs) Handles editDrgug.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If UGIDTxt.Text.Length.ToString > 0 And UGNAMETxt.Text.Length.ToString > 0 And UGNAME_ENTxt.Text.Length.ToString > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขวิธีการใช้ยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New DRGUGCLASS
                        objEditData.UGID_ = UGIDTxt.Text
                        objEditData.UGNAME_ = UGNAMETxt.Text
                        objEditData.UGNAME_EN_ = UGNAME_ENTxt.Text
                        objEditData.F_FOOD_ = F_FOODChk.Checked
                        objEditData.STATUS_ = STATUSChk.Checked

                        If objEditData.editMasdrgug() = True Then
                            MsgBox("ท่านได้ทำการแก้ไขรูปแบบการใช้ยาเรียบร้อยแล้ว")
                            queryDrgugGrid()
                            clearForm()
                            addDrgug.Enabled = True
                        End If
                    End If
                Else
                    MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วนก่อนทำการแก้ไขข้อมูล")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgug")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgug")
        nextform.ShowDialog()
    End Sub
End Class